/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio.processing.prediction.recset.reducers;

import aiaudio.database.tables.RatingsMatrixTable;
import aiaudio.database.tables.TemporaryMatrixTable;
import java.io.IOException;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableReducer;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.IntWritable;

/**
 *
 * @author nastya
 */
public class CopyAllArtistsJobReducer extends TableReducer<ImmutableBytesWritable, IntWritable, ImmutableBytesWritable> {
    public static final String ARTISTS_ARRAY = "artists";
    String[] users;

    @Override
    protected void reduce(ImmutableBytesWritable key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        Put put = new Put(key.get());
        for (String user : users) {
            TemporaryMatrixTable.addUserDummy(put, user);
        }
        context.write(new ImmutableBytesWritable(key), put);
    }

    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
        super.setup(context);
        users = context.getConfiguration().getStrings(ARTISTS_ARRAY);
    }
 
    
}
